<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@taglib prefix="s" uri="/struts-tags"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
	<head>
		<base href="<%=basePath%>">

		<title>编辑学生信息</title>

		<link rel="stylesheet"
			href="<%=request.getContextPath()%>/css/common.css" type="text/css" />
		<link rel="stylesheet"
			href="<%=request.getContextPath()%>/css/style.css" type="text/css" />
       <script type='text/javascript'
			src='<%=request.getContextPath()%>/js/sorttable.js'></script>
		<script type="text/javascript"
			src="<%=request.getContextPath()%>/js/N13FormValidation-2.js"></script>
		<script type='text/javascript'
			src='<%=request.getContextPath()%>/dwr/interface/dWRCollegeMajorAction.js'></script>
		<script type='text/javascript'
			src='<%=request.getContextPath()%>/dwr/interface/dormitoryAllocateAction.js'></script>
		<script type='text/javascript'
			src='<%=request.getContextPath()%>/dwr/interface/apartmentViewAction.js'></script>
		<script type='text/javascript'
			src='<%=request.getContextPath()%>/dwr/interface/studentLodgeMgrAction.js'></script>
		<script type='text/javascript'
			src='<%=request.getContextPath()%>/dwr/interface/studentAction.js'></script>		
		<script type='text/javascript'
			src='<%=request.getContextPath()%>/dwr/engine.js'></script>
		<script type='text/javascript'
			src='<%=request.getContextPath()%>/dwr/util.js'></script>
		<script type='text/javascript'
			src='<%=request.getContextPath()%>/js/jquery-latest.pack.js'></script>
		<script type="text/javascript"
			src="<%=request.getContextPath()%>/js/jqueryCopyEvent.js"></script>
		<script type="text/javascript"
			src="<%=request.getContextPath()%>/js/jquery.corner.js"></script>
		<script type='text/javascript'
			src='<%=request.getContextPath()%>/js/noConflictOfJquery.js'></script>
		<script type='text/javascript'
			src='<%=request.getContextPath()%>/js/forCSS.js'></script>
		<script type='text/javascript'
			src='<%=request.getContextPath()%>/dwr/interface/dormitoryStatusViewAction.js'></script>
		<script type='text/javascript'
			src='<%=request.getContextPath()%>/js/commonValidate.js'></script>
		<script type='text/javascript'
			src='<%=request.getContextPath()%>/js/tabcard.js'></script>
		
			
		<script type='text/javascript'>
		
		
		
//==================全局变量================
var stuno_bs;   //bs = basic student.  学号
//------------------全局变量结束-------------

//==================初始化开始================
/*
  document.onkeydown=subEv;
*/

$j(function (){
	  $('stumsc_textarea_bs').style.display = "none"; 
	  $('formSub').style.display = "none";
	 showAllCollege( $j("#collegeinfoid").get(0));//学院列表
	 showAllMajor($j("#majorinfoid").get(0));//专业列表
	
})
//------------------初始化结束-------------





//=================自定义函数开始===============

//验证输入是否有效
function validate_bs(){
	stuno_bs = strTrim_cv($('student_info').value);
	if(stuno_bs == ""){
			alert("请输入学号！");
			$('stumsc_textarea_bs').style.display = "none"; 
	        $('formSub').style.display = "none";
			return false;
	}
	if(!cnChar_cv(stuno_bs)){
			alert("您只能输入数字,字母和汉字,请重新输入");
			$('stumsc_textarea_bs').style.display = "none"; 
	        $('formSub').style.display = "none";
			return false;
	}
	return true;
}
//搜索学生信息
//对外的接口方法
function stu_BasicInfo(){
	
	var b = validate_bs();
	if(false == b){
		return ;
	}
   studentAction.searchStudentByStudentNo(stuno_bs,stu_BasicInfoCallback)
}
  var stu_BasicInfoCallback = function stu_BasicInfoCallbackFunc(stulist){
	//alert(stulist);
	$('notExist').style.display = 'none';
	if(stulist == null){
		$('notExist').style.display = '';
		$('stumsc_textarea_bs').style.display = "none"; 
	    $('formSub').style.display = "none";
		return;
	}
	//alert(stulist.length+"====="+stulist);
	  $('stumsc_textarea_bs').style.display = ""; 
	  $('formSub').style.display = "";
	var slist = eval('(' + stulist + ')');//JSON
	//alert(stulist);
	if($('studentno') != null){
		$('studentno').value = slist.studentno;
	}
	
	$('studentid').value = slist.studentid; //加上了隐藏的学生id
	$('studentno').value = slist.studentno;
	$('studentname').value = slist.studentname;

	
  	$('studentgender').value = slist.studentgender; 
  	$('collegeinfoid').value = slist.collegeinfoid;
 	$('majorinfoid').value = slist.majorinfoid;
 	$('studentclass').value = slist.studentclass;
 	$('studenttelephone').value = slist.studenttelephone;
 //	$('studentpicture').src="/dms"+slist[8];
 	$('studentethnic').value = slist.studentethnic;
    $('studentbirthplace').value = slist.studentbirthplace;
    $('studentbirthday').value = slist.studentbirthday;
    $('studenttype').value = slist.studenttype;
    $('studentidentitycardno').value=slist.studentidentitycardno;
    $('studentenrolltype').value = slist.studentenrolltype;
    $('studentadmissiontype').value = slist.studentadmissiontype; 
    $('studenteducationyears').value = slist.studenteducationyears; 
    $('studentenrollyear').value = slist.studentenrollyear; 
    $('studenthomeaddress').value = slist.studenthomeaddress; 
    $('studentarchivesaddress').value = slist.studentarchivesaddress; 
    $('studentmisc').value = slist.studentmisc;   
    
}



//enter键按下提交搜索

  function   subEv(event)   {  
	  event = event ? event : (window.event ? window.event : null);    
	  if(event.keyCode==13) {
	  	 stu_BasicInfo();
	  }
   
  } 

//输入学号的文本框被聚焦时
function stuno_button_onfocus_func_bs(){
	$j(document).bind("keydown",subEv);
}
//输入学号的文本框焦点离开时
function stuno_button_onblur_func_bs(){
	$j(document).unbind("keydown",subEv);
}
		
		
		
	    function isExistStuNo(){
			var result = false;
			var isExistStuNoCallback = function isExistStuNoCallbackFunc(count){
				if(count != 0){
					return result = true;
				}else{
					return result = false;
				}
			}
			DWREngine.setAsync(false);
			var a = studentAction.isExistStu($('studentno').value,"sno",isExistStuNoCallback);
			return !result;
		}
		
	
     
     	
		//显示所有的学院
		function showAllCollege(collegeObj){
			DWREngine.setAsync(false);  //dwr同步
			dWRCollegeMajorAction.getAllCollegeInfo(function (collegeList){
					if(null == collegeList){
						return;
					}
					var collegeInfo =collegeList;
					var s =collegeObj;
					 	DWRUtil.removeAllOptions(s);  
						s.options[0] = new Option("不限学院",'0');
			 		for ( var i = 1; i < collegeList.length+1; i++) {
						var opt = new Option(collegeList[i-1].collegeinfoname,
								collegeList[i-1].collegeinfoid);
						s.options[i] = opt;
					}
			});
			DWREngine.setAsync(true);  //恢复dwr异步
		}
		
//显示所有的专业,obj为显示下拉列表元素
		function showAllMajor(obj){
			DWREngine.setAsync(false);  //dwr同步
			dWRCollegeMajorAction. getAllMajorInfo(function (majorList){
					if(null == majorList){
						return;
					}
					var majorInfo =majorList;
					//alert(aptValue[0].apartmentfloornum);
					var s = obj;
					 	DWRUtil.removeAllOptions(s);  
						s.options[0] = new Option("不限专业",'0');
						//alert(majorList[0].majorinfoname)
					for ( var i = 1; i < majorList.length+1; i++) {
						var opt = new Option(majorList[i-1].majorinfoname,
								majorList[i-1].majorinfoid);
						s.options[i] = opt;
					}
			});
			DWREngine.setAsync(true);  //恢复dwr异步
		}
		//选择的学院变动的时候，专业联动 
		function selectedCollegeChange(collegeObj){
			majorObj = $j("#majorinfoid").get(0);
			if(collegeObj.options[collegeObj.selectedIndex].value == '0'){
				showAllMajor(majorObj);
				return;
			}
			showMajorByCollegeinfoid(collegeObj,collegeObj.options[collegeObj.selectedIndex].value);
			
		}
		//根据学院显示所有的专业
		function showMajorByCollegeinfoid(obj,collegeinfoid){
			dWRCollegeMajorAction.getMajorInfoByCollegeId(collegeinfoid, function  (majorList){
				var s =$j("#majorinfoid").get(0);
				if(majorList == null){
					DWRUtil.removeAllOptions(s); 
					s.options[0] = new
					 Option("不存在专业",'0');
					return;
				}
				var majorInfo =majorList;
				//alert(aptValue[0].apartmentfloornum);
				 	DWRUtil.removeAllOptions(s);  
					s.options[0] = new Option("不限专业",'0');
					//alert(majorList[0].majorinfoname)
				for ( var i = 1; i < majorList.length+1; i++) {
					var opt = new Option(majorList[i-1].majorinfoname,
							majorList[i-1].majorinfoid);
					s.options[i] = opt;
				}
			});
			
		}
		//选择的专业变动的时候，学院联动
		function selectedMajorChange(obj){
			major = obj;
			if(obj.options[obj.selectedIndex].value == '0'){
				return;
			}
			showCollegeByMajorInfoid(obj,obj.options[obj.selectedIndex].value);
		}
		//根据专业显示学院
		function showCollegeByMajorInfoid(obj,majorinfoid){
			dWRCollegeMajorAction.getCollegeInfoByMajorId(majorinfoid,function (collegeList){
				var college = $j("#collegeinfoid").get(0);
				for(var a=0;a<college.options.length;a++){
					if(college.options[a].value == collegeList[0].collegeinfoid){
						college.options[a].selected = "selected";
						break;
					}
				}
			});
		}
		</script>
	</head>

	<body>
	<div id="page_container">
		<jsp:include page="studentnav.jsp"></jsp:include>
		<h2>编辑学生信息</h2>
		
		<div id="student_basic_info_search">
		请输入学号：
		<input name="textfield" type="text" onfocus="stuno_button_onfocus_func_bs()" onblur="stuno_button_onblur_func_bs()" id="student_info"  />
		<input class="common_button" type="submit" name="button" id="button" value="搜索"
			onclick="stu_BasicInfo()" />
	   </div>
	<label id="notExist" style="display:none;color:'red';font-weight:bolder;" >学号不存在!</label>
			<s:form action="updatestudent.action" enctype="multipart/form-data" method="POST"
				id="updatestudent" theme="simple" >
				<s:hidden name="student.studentind" value="1" />				
				<s:hidden name="student.studentid" id="studentid" />
				<!-- 学生id的隐藏在这 -->
				<div id="student_id" style="display: none"></div>
				<table class="table_common" id="stumsc_textarea_bs">
					<tr>
						<td class="td_left">
							学号：
						</td>
						<td class="td_right">
							<s:textfield name="student.studentno" id="studentno" ></s:textfield>
						</td>
					</tr>
					<tr>
						<td class="td_left">
							选择学生照片：
						</td>						
						<td class="td_right">
							<s:file name="uploadedFile"></s:file>
						</td>
					</tr>
					
					
					<tr>
						<td class="td_left">
							姓名：
						</td>
						<td class="td_right">
							<s:textfield name="student.studentname" id="studentname"></s:textfield>
						</td>
					</tr>
					<tr>
						<td class="td_left">
							性别：
						</td>
						<td class="td_right">
						<select name="student.studentgender" id="studentgender"
									style="width: 40">
									<option value="男">
										男
									</option>
									<option value="女">
										女
									</option>
								</select>
						</td>
					</tr>
					<tr>
						<td class="td_left">
							出生日期：
						</td>
						<td class="td_right">
							<s:textfield name="student.studentbirthday " id="studentbirthday"></s:textfield>
							格式：YYYY-MM-DD
						</td>
					</tr>
					
					<tr>
						<td class="td_left">
							政治面貌：
						</td>
						<td class="td_right">
							<s:select cssClass="common_select" name="student.studentpolitics"  id="studentpolitics"
								list="#{'党员':'党员','预备党员':'预备党员','团员':'团员','群众':'群众','其他':'其他'}"
								value="'本科'" required="true" cssStyle="width:100px;"/>
						</td>
					</tr>
					<tr>
						<td class="td_left">
							身份证号：
						</td>
						<td class="td_right">
							<s:textfield name="student.studentidentitycardno"
								id="studentidentitycardno"></s:textfield>
						</td>
					</tr>
					<tr>
						<td class="td_left">
							生源地：
						</td>
						<td class="td_right">
							<s:textfield name="student.studentbirthplace"
								id="studentbirthplace"></s:textfield>
						</td>
					</tr>
					<tr>
						<td class="td_left">
							民族：
						</td>
						<td class="td_right">
							<s:textfield name="student.studentethnic" id="studentethnic"></s:textfield>
						</td>
					</tr>
					
					<tr>
					<td class="td_left">
					        学院：
					 </td>
					 <td class="td_right">
					<select  name="student.collegeinfoid" id="collegeinfoid" style="width: 153px;" onchange="selectedCollegeChange(this)" >
					</select>
					</td>
					</tr>
					<tr>
					<td class="td_left">
					 	专业：
					 </td>
					 <td class="td_right">
					<select  name="student.majorinfoid" id="majorinfoid" style="width: 153px;" onchange="selectedMajorChange(this)">
					</select>
					</td>
					</tr>
					
					<tr>
					<td class="td_left">
					班级：
					</td>
					<td class="td_right">
					<s:textfield name="student.studentclass" id="studentclass"></s:textfield>
					</td>
					</tr>
					
					
				
					<tr>
						<td class="td_left">
							学生类型：
						</td>
						<td class="td_right">
							<s:select cssClass="common_select" name="student.studenttype" id="studenttype"
								list="#{'预科':'预科','本科':'本科','硕士':'硕士研究生','博士研究生':'博士研究生','博士后':'博士后'}"
								value="'本科'" required="true" cssStyle="width:100px;"/>
						</td>
					</tr>
					<tr>
						<td class="td_left">
							招生类别：
						</td>
						<td class="td_right">
							<s:select cssClass="common_select"  name="student.studentenrolltype" id="studentenrolltype"
								list="#{'预科':'预科','本科':'本科','硕士研究生':'硕士研究生','博士研究生':'博士研究生','博士后':'博士后'}"
								value="'本科'" required="true" cssStyle="width:100px;" />
						</td>
					</tr>
					<tr>
						<td class="td_left">
							学制：
						</td>
						<td class="td_right">
							<s:select cssClass="common_select"  name="student.studenteducationyears" id="studenteducationyears"
								list="#{'4':'4年制','5':'5年制','3':'2.5年制'}" value="'4'" required="true" cssStyle="width:100px;" />
						</td>
					</tr>
					<tr>
						<td class="td_left">
							录取类别：
						</td>
						<td class="td_right">
							<s:select cssClass="common_select"  name="student.studentadmissiontype" id="studentadmissiontype"
								list="#{'预科':'预科','本科':'本科','硕士研究生':'硕士研究生','博士研究生':'博士研究生','博士后':'博士后'}"
								value="'本科'" required="true"  cssStyle="width:100px;"/>
						</td>
					</tr>
					<tr>
						<td class="td_left">
							入学年份：
						</td>
						<td class="td_right">
							<s:select cssClass="common_select"  name="student.studentenrollyear" id="studentenrollyear"
								list="#{'2003':'2003','2004':'2004','2005':'2005','2006':'2006','2007':'2007','2008':'2008','2009':'2009'}"
								value="'2009'" required="true" cssStyle="width:100px;" />
						</td>
					</tr>
					<tr>
						<td class="td_left">
							联系电话：
						</td>
						<td class="td_right">
							<s:textfield name="student.studenttelephone"
								id="studenttelephone"></s:textfield>
						</td>
					</tr>
					<tr>
						<td class="td_left">
							通信地址：
						</td>
						<td class="td_right">
							<s:textfield name="student.studenthomeaddress"
								id="studenthomeaddress"></s:textfield>
						</td>
					</tr>
					<tr>
						<td class="td_left">
							档案所在地：
						</td>
						<td class="td_right">
							<s:textfield name="student.studentarchivesaddress"
								id="studentarchivesaddress"></s:textfield>
						</td>
					</tr>
					<tr>
						<td class="td_left">
							备注：
						</td>
						<td class="td_right">
							<s:textfield name="student.studentmisc" id="studentmisc"></s:textfield>
						</td>
					</tr>
				</table>
				<s:submit cssClass="common_button" id="formSub" value="提交"></s:submit>
			</s:form>
		</div>
		<script type="text/javascript">
			N13.register('updatestudent',[
					
					{
						id:'studentno',
						type:'Required',
						validMsg:'√',
						validOnBlur:true,
						renderValid:true
					},
					
					
					{
						id:'studentname',
						type:'Required', 
						validMsg:'√',
						validOnBlur:true,
						renderValid:true
					},
					{
						id:'studentbirthday',
						type:'format',
						validMsg:'√',
						validOnBlur:true,
						renderValid:true,
						pattern: /^(\d{4})-(0\d{1}|1[0-2])-(0\d{1}|[12]\d{1}|3[01])$/i
					},
					
					{
						id:'studentidentitycardno',
						type:'Required',
						validMsg:'√',
						validOnBlur:true,
						renderValid:true
					},
					{
						id:'studenttelephone',
						type:'format',
						validMsg:'√',
						validOnBlur:true,
						renderValid:true,
						pattern: /^[+]{0,1}(\d){1,3}[ ]?([-]?((\d)|[ ]){1,12})+$/i
					}
					
				]);
			window.onload = function(){
				var nav_a=$j('#page_nav a');
				var nav_span=$j("#page_nav a span");
				for(var u = 0 ;u<nav_a.length;u++){
						nav_a.get(u).style.backgroundPosition="left top";
						nav_span.get(u).style.backgroundPosition="right top";							
				}
				$j('#page_nav a').get(0).style.backgroundPosition="0% -42px";
				$j("#page_nav a span").get(0).style.backgroundPosition="100% -42px";
			}	
			</script>
	</body>
</html>
					